<template>
    <a-modal :title="titlePrefix+'${tableName}'" :visible="visible" centered destroyOnClose mask :maskClosable="false"
             :confirmLoading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
        <a-form :form="form" layout="horizontal" @submit="handleSubmit">
            <!--可编辑区域-->
            <div class="hide">
                <a-form-item><a-input v-decorator="decorator.id"/></a-form-item>
            </div><#list columns as d><#if d.colName!='updateTime' && d.colName!='status' && d.colName!='created'>
            <a-form-item label="${d.remark}" :label-col="formItemLayout.labelCol" :wrapper-col="formItemLayout.wrapperCol">
            <a-input v-decorator="decorator.${d.colName}" placeholder="请输入${d.remark}" size="large"/>
			</a-form-item></#if></#list>
            <!--可编辑区域 end-->
        </a-form>
    </a-modal>
</template>

<script>
    import {modalMixin} from "../../../../mixins/modalMixin";
    import {dataCheck} from "../../../../common/dataCheck";
    import pick from 'lodash.pick'
    export default {
        name: "addOrEditModal",
        mixins: [modalMixin],
        data() {
            return {
                /*表单布局标题宽度 根据实际效果修改*/
                formItemLayout: {
                    labelCol: {span: 8},
                    wrapperCol: {span: 10},
                },
                /*表单绑定值与验证规则定义*/
                decorator: {<#list columns as d><#if d.colName!='updateTime' && d.colName!='status' && d.colName!='created'>
                    ${d.colName}: ['${d.colName}', {rules: [<#if d.pk != d.colName>dataCheck.required()</#if>]}],</#if></#list>
                },

                /*提交表单地址*/
                submitUrl: '${requestPrefix}/${tableSubName?uncap_first}/saveOrUpdate',
            }
        },
        methods: {
            /*获取编辑表单详细内容，方法名不可修改*/
            getEditInfo(record) {
                /*record可传完整数据，或根据record查询接口返回全部数据*/
                let self = this, editInfo = record;
                /*个别数据需要特别格式处理 在这里处理*/
                self.$nextTick().then(() => {
                    self.form.setFieldsValue(
                        pick(editInfo, self.getEditInfoArr())
                    )
                })
            },
        }
    }
</script>

<style scoped>

</style>